//
//  MessagesViewController.m
//  atXiaoGeBClient
//
//  Created by Linyu Niu on 20/04/2018.
//  Copyright © 2018 Linyu Niu. All rights reserved.
//

#import "MessagesViewController.h"

@interface MessagesViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    NSArray * dataList;
    UITableView * msgTableView;
}
@end

@implementation MessagesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    __weak MessagesViewController * weakSelf = self;
    UIView * navView = [[CTMediator sharedInstance] navgationHeadViewInTargetView:self.view params:[NSDictionary dictionaryWithObjectsAndKeys:@"消息",@"title", nil] leftAction:^(UIButton *sender){
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } rightAction:^(UIButton *sender){
        
    }];
    msgTableView = [self addTableViewInView:self.view frame:CGRectMake(0, navView.frame.size.height + navView.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height - (navView.frame.size.height + navView.frame.origin.y)) delegateAndDataSource:self];
    msgTableView.backgroundColor = [UIColor colorWithRed:240.0 / 255.0 green:240.0 / 255.0 blue:240.0 / 255.0 alpha:1.0];
    [[CTMediator sharedInstance] messageListblock:^(NSDictionary *dic){
        
    }];
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ElementTableViewCell * cell = [[ElementTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.backgroundColor = [UIColor clearColor];
    
    UIView * bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 15, tableView.frame.size.width, 0)];
    bgView.backgroundColor = [UIColor whiteColor];
    [cell addSubview:bgView];
    
    
    UILabel * nameLabel = [[UILabel alloc] init];
    nameLabel.frame = CGRectMake(15, 15, tableView.frame.size.width - 30, 25);
    
    nameLabel.font = [UIFont systemFontOfSize:16];
    nameLabel.textColor = [UIColor colorWithRed:51.0/255.0 green:51.0/255.0 blue:51.0/255.0 alpha:1.0];
    [bgView addSubview:nameLabel];
    
    
    UILabel * timeLabel = [[UILabel alloc] init];
    timeLabel.frame = CGRectMake(0, nameLabel.frame.origin.y, tableView.frame.size.width - nameLabel.frame.origin.x, nameLabel.frame.size.height);
    
    timeLabel.font = [UIFont systemFontOfSize:13];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
    [bgView addSubview:timeLabel];
    
    
    UILabel * desLabel = [[UILabel alloc] init];
    desLabel.frame = CGRectMake(nameLabel.frame.origin.x, nameLabel.frame.size.height + nameLabel.frame.origin.y, nameLabel.frame.size.width, 0);
    desLabel.numberOfLines = 0;
    
    desLabel.font = [UIFont systemFontOfSize:13];
    desLabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1.0];
    [bgView addSubview:desLabel];
    
#if kDevelopment
    desLabel.text = @"您有新的订单待抢，请查看抢单列表。";
    timeLabel.text = @"08-28 10：00";
    nameLabel.text = @"抢单喽";
#endif
         [desLabel enlargeHeightToKeepFontSizeWithMinHeight:nameLabel.frame.size.height];
    
    bgView.frame = CGRectMake(bgView.frame.origin.x, bgView.frame.origin.y, bgView.frame.size.width, desLabel.frame.size.height + desLabel.frame.origin.y + nameLabel.frame.origin.y);
    
    cell.cellHeight = bgView.frame.size.height + bgView.frame.origin.y;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ElementTableViewCell * cell = (ElementTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHeight;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
#if kDevelopment
    return 10;
#endif
    return [dataList count];
}
@end
